﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;


using Jungle.Code.Utils;
using Jungle.Prodamo.PriceManager;

namespace Jungle.Prodamo.User.WebControls
{
    public class CategoryTree2 : WebControl
    {
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.AddAttribute("class", "advm_table");
            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute("class", "advm_td");
            writer.AddAttribute("colspan", "2");
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write("Прайс-листы: новые категрии");
            writer.RenderEndTag();
            writer.RenderEndTag();

            Category cats = new Category();
            Category cat;
            List<Category> Parrents = cats.GetParrents();
            int i = Parrents.Count - 11;
            while (i < Parrents.Count)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                for (int z = 0; z < 2; z++)
                {
                    if (!(i < Parrents.Count)) break;
                    cat = Parrents[i];
                    writer.AddAttribute("style", "width: 50%;");
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);

                    writer.Write("<table><tr><td>");
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + "/ru/price.aspx?Id=" + cat.CategoryId.ToString());
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, UrlHelper.GetSiteUrl() + cat.ImageUrl.Substring(1));
                    writer.RenderBeginTag(HtmlTextWriterTag.Img);
                    writer.RenderEndTag();
                    writer.RenderEndTag();
                    writer.Write("</td><td>");
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + "/ru/price.aspx?Id=" + cat.CategoryId.ToString());
                    writer.AddAttribute("style", "font-size: 16px; font-family: Arial; color: #154e73; font-weight: bold;");
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write(cat.Name + "<br/>");
                    writer.RenderEndTag();
                    List<Category> Childs = cat.GetChilds();
                    foreach (Category c in Childs)
                    {
                        if (c.ImageUrl.IndexOf("px") == -1)
                        {
                            writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + "/ru/price.aspx?Id=" + c.CategoryId.ToString());
                            writer.AddAttribute("style", "font-size: 12px; font-family: Arial; color: #154e73;");
                            writer.RenderBeginTag(HtmlTextWriterTag.A);
                            writer.Write(c.Name);
                            writer.RenderEndTag();
                            writer.Write(",&nbsp;");
                        }
                    }
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, UrlHelper.GetSiteUrl() + "/ru/price.aspx?Id=" + cat.CategoryId.ToString());
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.Write("...");
                    writer.RenderEndTag();
                    writer.Write("</td></tr></table>");
                    writer.RenderEndTag();
                    i++;
                }

                writer.RenderEndTag();
             }
            writer.RenderEndTag();


            base.RenderContents(writer);
        }
    }
}
